<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>部门选择控件</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
    <link rel="stylesheet" href="../formdesign/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../../../css/ueditor/site.css">
    <script type="text/javascript" src="../dialogs/internal.js"></script>
    <script type="text/javascript" src="../../../js/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../../js/base/base.js"></script>
    <script type="text/javascript">
        function createElement(type, name)
        {
            var element = null;
            try {
                element = document.createElement('<'+type+' name="'+name+'">');
            } catch (e) {}
            if(element==null) {
                element = document.createElement(type);
                element.name = name;
            }
            return element;
        }
    </script>
</head>
<body>
<div class="content">
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <th colspan="2"><span>控件名称</span><span class="label label-important">*</span></th>
        </tr>
        <tr>
            <td  colspan="2">
                <input id="orgname" type="text" placeholder="必填项"/>
            </td>
        </tr>
        <tr>
            <th colspan="2"><span>属性</span></th>
        </tr>
        <tr>
            <td colspan="2">
                宽 <input id="orgwidth" type="text" value="150" class="input-small span1" placeholder="auto"/> px
                &nbsp;&nbsp;
                高 <input id="orgheight" type="text" value="" class="input-small span1" placeholder="auto"/> px
                &nbsp;&nbsp;
                字体 <input id="orgfontsize" type="text" value="" class="input-small span1" placeholder="auto"/> px
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    $(function () {
        var oNode = null,thePlugins = 'deptselect';
        var dataid = $.getQueryString('dataid');
        var dataNumber=parent.pluginId;
        if( UE.plugins[thePlugins].editdom ) {
            oNode = UE.plugins[thePlugins].editdom;
            var gTitle=oNode.getAttribute('title').replace(/&quot;/g,"\""),
                gFontSize=oNode.getAttribute('orgfontsize'),
                gWidth=oNode.getAttribute('orgwidth'),
                gHeight=oNode.getAttribute('orgheight');

            gTitle = gTitle==null ? '' : gTitle;

            $G('orgname').value    = gTitle;
            $G('orgwidth').value = gWidth;
            $G('orgheight').value = gHeight;
            $G('orgfontsize').value = gFontSize;
        }


        dialog.oncancel = function () {
            if( UE.plugins[thePlugins].editdom ) {
                delete UE.plugins[thePlugins].editdom;
            }
        };
        dialog.onok = function (){
            if ( $G('orgname').value == '' ) {
                alert('控件名称不能为空');
                return false;
            }
            var gTitle=$G('orgname').value.replace(/\"/g,"&quot;"),
                gWidth=$G('orgwidth').value,
                gFontSize=$G('orgfontsize').value,
                gHeight=$G('orgheight').value;
            if( !oNode ) {
                try {
                    var html = '<textarea ';
                    html += ' name =  "' + 'DATA_'+dataNumber + '"';
                    html += ' id =  "' + 'DATA_'+dataNumber + '"';
                    html += ' class = "' + 'form_item deptselect' + '"';
                    html += ' data-type = "' + 'deptselect' + '"';
                    html += ' title = "' + gTitle + '"';
                    html += ' readonly = "readonly"';
                    if( gFontSize != '' ) {
                        html += ' orgfontsize = "' + gFontSize + '"';
                    } else {
                        html += ' orgfontsize = ""';
                    }
                    if( gWidth != '' ) {
                        html += ' orgwidth = "' + gWidth + '"';
                    } else {
                        html += ' orgwidth = ""';
                    }
                    if(gHeight != '') {
                        html += ' orgheight = "' + gHeight + '"';
                    } else {
                        html += ' orgheight = ""';
                    }
                    html += '></textarea>';
                    html = $(html);
                    html.attr("style","cursor: pointer;background: #fff url(/img/workflow/form/group_select.png) no-repeat right;"+'height:'+gHeight+'px;width:'+gWidth+'px;font-size:'+gFontSize+'px;');

                    editor.execCommand('insertHtml',html.prop("outerHTML"));
                    return true;
                } catch ( e ) {
                    try {
                        editor.execCommand('error');
                    } catch ( e ) {
                        alert(控件异常);
                    }
                    return false;
                }
            } else {

                oNode.setAttribute('class', "form_item deptselect");
                oNode.setAttribute('data-type', "deptselect");
                oNode.setAttribute('style', "cursor: pointer;background: #fff url(/img/workflow/form/group_select.png) no-repeat right;");
                oNode.setAttribute('title',gTitle);
                oNode.setAttribute('name','DATA_'+dataNumber);
                oNode.setAttribute('id','DATA_'+dataNumber);
                oNode.setAttribute('readonly','readonly');
                if (gHeight != '') {
                    oNode.style.height = gHeight + 'px';
                }
                if (gWidth != '') {
                    oNode.style.width = gWidth + 'px';
                }
                if (gFontSize != '') {
                    oNode.style.fontSize = gFontSize + 'px';
                }
                oNode.setAttribute('orgwidth',gWidth);
                oNode.setAttribute('orgheight',gHeight);
                oNode.setAttribute('orgfontsize',gFontSize);

                delete UE.plugins[thePlugins].editdom;
            }
        };

    });

</script>
</body>
</html>
